package com.miku.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miku.blog.domain.*;
import com.miku.blog.domain.dto.CommentDTO;
import com.miku.blog.domain.param.ReceptionParam;
import com.miku.blog.domain.pojo.LoginUser;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.domain.pojo.SystemConstance;
import com.miku.blog.domain.vo.CommentVo;
import com.miku.blog.domain.vo.PageVo;
import com.miku.blog.eume.HttpStatusEnum;
import com.miku.blog.exception.SystemException;
import com.miku.blog.service.*;
import com.miku.blog.mapper.CommentMapper;
import com.miku.blog.utils.BeanCopyUtils;
import com.miku.blog.utils.InsertSortUtils;
import com.miku.blog.utils.RedisCache;
import com.miku.blog.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Miku
 * @description 针对表【tb_comment】的数据库操作Service实现
 * @createDate 2022-05-26 17:53:41
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment>
        implements CommentService {

    @Autowired
    private UserInfoService userInfoService;
    @Lazy
    @Autowired
    private ArticleService articleService;
    @Autowired
    private LikeCountService likeCountService;
    @Autowired
    private TalkService talkService;
    @Autowired
    private RedisCache redisCache;


    @Override
    public boolean deleteCommentByArticleIdAndType(Integer articleId, Integer type) {

        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.clear();
        queryWrapper.eq(Comment::getArticleId, articleId)
                .eq(Comment::getType, type);
//        if (remove(queryWrapper)){
//            delRedisCacheByArticleIdAndType(articleId,type);//删除redis缓存中的相关数据
//            return true;
//        }else {
//            return false;
//        }
        return remove(queryWrapper);
    }


    @Transactional
    @Override
    public ResponseResult deleteCommentListById(Integer[] commentIdList) {

//        List<Comment> commentList = new ArrayList<>();
        for (Integer commentId : commentIdList) {
            Comment comment = getById(commentId);
            if (comment.getParentId().equals(SystemConstance.COMMENT_ROOT_ID)) {
                //若当前评论为根，则其子评论也一并删除
                List<Comment> childrenList = getChildrenListById(commentId,null);
                if (Objects.nonNull(childrenList) && childrenList.size() > 0) {
                    childrenList.stream()
                            .peek(var1 -> {
                                Integer id = var1.getId();
                                likeCountService.delLikeCountByTargetIdAndType(id,SystemConstance.LIKE_COUNT_TYPE_BY_COMMENT);
                                if (!removeById(id)) {
                                    throw new SystemException(HttpStatusEnum.REMOVE_DATA_ERROR);
                                }
                            }).collect(Collectors.toList());
                }
            }
//            commentList.add(comment);//存入List集合中 用于删除redis缓存中的相关数据
            likeCountService.delLikeCountByTargetIdAndType(commentId,SystemConstance.LIKE_COUNT_TYPE_BY_COMMENT);
            if (!removeById(commentId)) {
                throw new SystemException(HttpStatusEnum.REMOVE_DATA_ERROR);
            }
        }
//        delRedisCacheByComments(commentList);//删除redis缓存中的相关数据
        return ResponseResult.ok();
    }

    @Override
    public ResponseResult comments(Integer current,
                                   Integer size,
                                   @Nullable Integer type,
                                   @Nullable Integer isReview,
                                   @Nullable String keywords) {

        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();

        List<Comment> commentList;

        int total;

        if (!StringUtils.hasText(keywords)) {
            Page<Comment> page = new Page<>(current, size);
            queryWrapper.eq(Objects.nonNull(type), Comment::getType, type)
                    .eq(Objects.nonNull(isReview), Comment::getIsReview, isReview)
                    .orderByDesc(Comment::getCreateTime);
            page(page, queryWrapper);
            commentList = page.getRecords();
            commentList.stream()
                    .peek(comment -> {
                        UserInfo userInfo = userInfoService.getUserInfoByUserId(comment.getUserId());
                        comment.setAvatar(userInfo.getAvatar())
                                .setNickname(userInfo.getNickname());
                    }).collect(Collectors.toList());
            total = (int) page.getTotal();
        } else {
            //若根据用户昵称查询相关评论,则先获取对应条件的用户信息,再获取相关评论
            commentList = new ArrayList<>();
            List<UserInfo> userInfoList = userInfoService.getAllUserInfoListByNickName(keywords);
            for (UserInfo userInfo : userInfoList) {
                queryWrapper.clear();
                queryWrapper.eq(Comment::getUserId, userInfo.getUserId())
                        .eq(Objects.nonNull(type), Comment::getType, type)
                        .eq(Objects.nonNull(isReview), Comment::getIsReview, isReview)
                        .orderByDesc(Comment::getCreateTime);
                List<Comment> comments = list(queryWrapper);
                comments.stream()
                        .peek(comment -> {
                            comment.setAvatar(userInfo.getAvatar())
                                    .setNickname(userInfo.getNickname());
                        }).collect(Collectors.toList());
                if (comments.size() > 0) {
                    commentList.addAll(comments);
                }
            }

            InsertSortUtils.insertSortByCommentCreateTimeDown(commentList);

            total = commentList.size();

            if (total > (current * size)) {
                commentList = commentList.subList((current - 1) * size, current * size);
            } else if (total > ((current - 1) * size)) {
                commentList = commentList.subList((current - 1) * size, total);
            } else {
                commentList = null;
            }
        }

        List<CommentVo> commentVoList = null;
        if (Objects.nonNull(commentList) && commentList.size() > 0) {
            List<Comment> comments
                    = commentList.stream()
                    .peek(comment -> {
                        if (SystemConstance.COMMENT_TYPE_BY_ARTICLE_CODE.equals(comment.getType())) {
                            Article article = articleService.getById(comment.getArticleId());
                            comment.setArticleTitle(article.getArticleTitle());
                        }
                        Integer replyId = comment.getReplyId();
                        if (!SystemConstance.COMMENT_ROOT_ID.equals(replyId)) {
                            UserInfo replyUserInfo = userInfoService.getUserInfoByUserId(replyId);
                            comment.setReplyNickname(replyUserInfo.getNickname());
                        }
                    }).collect(Collectors.toList());
            commentVoList = BeanCopyUtils.copyListByType(comments, CommentVo.class);
        }
        PageVo<CommentVo> pageVo = new PageVo((long) total, commentVoList);
        return ResponseResult.ok().setData(pageVo);
    }


    private List<Comment> getChildrenListById(Integer id,Integer isReview) {

        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getParentId, id)
                .eq(Objects.nonNull(isReview),Comment::getIsReview,isReview);
        List<Comment> comments = list(queryWrapper);
        if (Objects.isNull(comments) || comments.size() <= 0) {
            return null;
        }
        ArrayList<Comment> arrayList = new ArrayList<>();
        for (Comment comment : comments) {
            List<Comment> children = getChildrenListById(comment.getId(),isReview);
            if (Objects.nonNull(children) && children.size() > 0) {
                arrayList.addAll(children);
            }
        }
        if (arrayList.size() > 0) {
            comments.addAll(arrayList);
        }
        return comments;
    }


    @Override
    public ResponseResult getComments(Integer current, Integer type, Integer articleId) {

        if (SystemConstance.COMMENT_TYPE_BY_ARTICLE_CODE.equals(type)) {
            Article article = articleService.getById(articleId);
            if ((SystemConstance.STATUS_PRIVATE.equals(article.getStatus()) && !checkAdmin())
                    || SystemConstance.ARTICLE_STATUS_DRAFT.equals(article.getStatus())) {
                return ResponseResult.ok();
            }
        }else if (SystemConstance.COMMENT_TYPE_BY_TALK_CODE.equals(type)){
            Talk talk = talkService.getById(articleId);
            if (SystemConstance.STATUS_PRIVATE.equals(talk.getStatus()) && !checkAdmin()) {
                return ResponseResult.ok();
            }
        }

        Page<Comment> page = new Page<>(current, SystemConstance.PAGE_SIZE);
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Objects.nonNull(articleId), Comment::getArticleId, articleId)
                .eq(Comment::getType, type)
                .eq(Comment::getParentId, SystemConstance.COMMENT_ROOT_ID)
                .eq(Comment::getIsReview, SystemConstance.IS_REVIEW)
                .orderByAsc(Comment::getCreateTime);
        page(page, queryWrapper);
        List<CommentDTO> rootCommentDTOS = BeanCopyUtils.copyListByType(page.getRecords(), CommentDTO.class);
        long total = page.getTotal();
        for (CommentDTO dto : rootCommentDTOS) {
//            List<Comment> cacheChildrenList = getRedisChildrenCommentListByRootCommentIdAndType(dto.getId().toString(),dto.getType());
//            List<Comment> childrenList;
//            if (Objects.isNull(cacheChildrenList) || cacheChildrenList.size() <= 0) {
//                childrenList = getChildrenListById(dto.getId(),SystemConstance.IS_REVIEW);
//                InsertSortUtils.insertSortByCommentCreateTimeUp(childrenList);
//                setRedisCacheChildrenCommentList(dto.getId().toString(), dto.getType(), childrenList);
//            } else {
//                childrenList = cacheChildrenList;
//            }
            List<Comment> childrenList = getChildrenListById(dto.getId(),SystemConstance.IS_REVIEW);
            if (Objects.nonNull(childrenList)) {
                InsertSortUtils.insertSortByCommentCreateTimeUp(childrenList);
                int size = childrenList.size();
//                total += size;
                dto.setReplyCount(size);
                if (size > (SystemConstance.PAGE_CURRENT_MIN * SystemConstance.COMMENT_PAGE_SIZE)) {
                    childrenList = childrenList.subList((SystemConstance.PAGE_CURRENT_MIN - 1) * SystemConstance.COMMENT_PAGE_SIZE, SystemConstance.PAGE_CURRENT_MIN * SystemConstance.COMMENT_PAGE_SIZE);
                } else if (size > ((SystemConstance.PAGE_CURRENT_MIN - 1) * SystemConstance.COMMENT_PAGE_SIZE)) {
                    childrenList = childrenList.subList((SystemConstance.PAGE_CURRENT_MIN - 1) * SystemConstance.COMMENT_PAGE_SIZE, size);
                } else {
                    childrenList = null;
                }
                List<CommentDTO> childrenDTOList = null;
                if (Objects.nonNull(childrenList)) {
                    childrenDTOList = BeanCopyUtils.copyListByType(childrenList, CommentDTO.class);
                    childrenDTOList.stream()
                            .peek(commentDTO -> {

                                UserInfo userInfo = userInfoService.getUserInfoByUserId(commentDTO.getUserId());
                                UserInfo replyInfo = userInfoService.getUserInfoByUserId(commentDTO.getReplyId());
                                commentDTO.setAvatar(userInfo.getAvatar())
                                        .setWebSite(userInfo.getWebSite())
                                        .setNickname(userInfo.getNickname())
                                        .setReplyNickname(replyInfo.getNickname())
                                        .setReplyWebSite(replyInfo.getWebSite());

                                long commentLikeCount = likeCountService.getLikeCountByTargetIdAndType(commentDTO.getId(),SystemConstance.LIKE_COUNT_TYPE_BY_COMMENT);
                                commentDTO.setLikeCount((int) commentLikeCount);

                            }).collect(Collectors.toList());
                }

                dto.setReplyDTOList(childrenDTOList);
            }

            long commentLikeCount = likeCountService.getLikeCountByTargetIdAndType(dto.getId(),SystemConstance.LIKE_COUNT_TYPE_BY_COMMENT);
            UserInfo userInfo = userInfoService.getUserInfoByUserId(dto.getUserId());
            dto.setAvatar(userInfo.getAvatar())
                    .setWebSite(userInfo.getWebSite())
                    .setNickname(userInfo.getNickname())
                    .setLikeCount((int) commentLikeCount);

        }


        PageVo<CommentDTO> pageVo = new PageVo(total, rootCommentDTOS);
        return ResponseResult.ok().setData(pageVo);
    }

    @Override
    public ResponseResult getChildrenComments(Integer commentId, Integer current, Integer size) {
//        Comment comment = getById(commentId);
//        List<Comment> childrenList = getRedisChildrenCommentListByRootCommentIdAndType(commentId.toString(),comment.getType());
//        if (Objects.isNull(childrenList) || childrenList.size() <= 0) {
//
//            childrenList = getChildrenListById(commentId,SystemConstance.IS_REVIEW);
//            InsertSortUtils.insertSortByCommentCreateTimeUp(childrenList);
//            setRedisCacheChildrenCommentList(commentId.toString(), comment.getType(), childrenList);
//
//        }
        List<Comment> childrenList = getChildrenListById(commentId,SystemConstance.IS_REVIEW);
        if (Objects.nonNull(childrenList)) {
            InsertSortUtils.insertSortByCommentCreateTimeUp(childrenList);
            int childrenSize = childrenList.size();

            if (childrenSize > (current * size)) {
                childrenList = childrenList.subList((current - 1) * size, current * size);
            } else if (childrenSize > ((current - 1) * size)) {
                childrenList = childrenList.subList((current - 1) * size, childrenSize);
            } else {
                childrenList = null;
            }
        }
        List<CommentDTO> commentDTOS = null;
        if (Objects.nonNull(childrenList)) {
            commentDTOS = BeanCopyUtils.copyListByType(childrenList, CommentDTO.class);
            commentDTOS.stream()
                    .peek(commentDTO -> {

                        UserInfo userInfo = userInfoService.getUserInfoByUserId(commentDTO.getUserId());
                        UserInfo replyInfo = userInfoService.getUserInfoByUserId(commentDTO.getReplyId());
                        commentDTO.setWebSite(userInfo.getWebSite())
                                .setNickname(userInfo.getNickname())
                                .setAvatar(userInfo.getAvatar())
                                .setReplyWebSite(replyInfo.getWebSite())
                                .setReplyNickname(replyInfo.getNickname());

                        long commentLikeCount = likeCountService.getLikeCountByTargetIdAndType(commentDTO.getId(),SystemConstance.LIKE_COUNT_TYPE_BY_COMMENT);
                        commentDTO.setLikeCount((int) commentLikeCount);

                    }).collect(Collectors.toList());
        }
        return ResponseResult.ok().setData(commentDTOS);
    }




    @Transactional
    @Override
    public ResponseResult updateComment(ReceptionParam receptionParam) {
        Integer isReview = receptionParam.getIsReview();
        List<Integer> idList = receptionParam.getIdList();
        if (!SystemConstance.IS_REVIEW.equals(isReview) && !SystemConstance.NOT_REVIEW.equals(isReview)) {
            return new ResponseResult(HttpStatusEnum.PARAM_ERROR);
        }

        LambdaUpdateWrapper<Comment> updateWrapper = new LambdaUpdateWrapper<>();
        for (Integer commentId : idList) {
            updateWrapper.clear();
            updateWrapper.eq(Comment::getId, commentId)
                    .set(Comment::getIsReview, isReview);
            if (!update(updateWrapper)) {
                throw new SystemException(HttpStatusEnum.UPDATE_DATA_ERROR);
            }
        }
//        delRedisCacheByCommentIds(idList);
        return ResponseResult.ok();
    }



    @Override
    public ResponseResult addComment(Comment comment){
        Integer type = comment.getType();
        String commentContent = comment.getCommentContent();
        Integer articleId = comment.getArticleId();
        if (Objects.isNull(type)
                || !StringUtils.hasText(commentContent)
                || (!SystemConstance.COMMENT_TYPE_BY_ARTICLE_CODE.equals(type) && !SystemConstance.COMMENT_TYPE_BY_FRIEND_LINK_CODE.equals(type) && !SystemConstance.COMMENT_TYPE_BY_TALK_CODE.equals(type))
                || (Objects.isNull(articleId) && !SystemConstance.COMMENT_TYPE_BY_FRIEND_LINK_CODE.equals(type))
        ){
            return new ResponseResult(HttpStatusEnum.PARAM_ERROR);
        }

        //确保回复人 / 回复的文章真实存在
        Integer parentId = comment.getParentId();
        Integer replyId = comment.getReplyId();
        if (Objects.nonNull(parentId) || Objects.nonNull(replyId)){
            LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Comment::getId,parentId)
                    .eq(Comment::getUserId,replyId);
            Comment query = getOne(queryWrapper);
            if (Objects.isNull(query)){
                return new ResponseResult(HttpStatusEnum.DATA_EXCEPTIONS);
            }
        }
        //articleId 未NULL 则 评论类型为友链
        if (Objects.nonNull(articleId)){

            if (SystemConstance.COMMENT_TYPE_BY_ARTICLE_CODE.equals(type)) {
                Article article = articleService.getById(articleId);
                if (Objects.isNull(article)){
                    return new ResponseResult(HttpStatusEnum.DATA_EXCEPTIONS);
                }
            }else if (SystemConstance.COMMENT_TYPE_BY_TALK_CODE.equals(type)){
                Talk talk = talkService.getById(articleId);
                if (Objects.isNull(talk)){
                    return new ResponseResult(HttpStatusEnum.DATA_EXCEPTIONS);
                }
            }

        }


        Integer isCommentReview = redisCache.getCacheHashMapValue(SystemConstance.REDIS_WEBSITE_CONFIG_REVIEW_HASH_KEY,
                SystemConstance.REDIS_WEBSITE_IS_COMMENT_REVIEW_KEY);
        if (isCommentReview.equals(SystemConstance.OPEN_WEBSITE_CONFIG)){
            comment.setIsReview(SystemConstance.NOT_REVIEW);
        }else {
            comment.setIsReview(SystemConstance.IS_REVIEW);
        }

        comment.setUserId(SecurityUtils.getUserAuth().getId())
                .setCreateTime(new Date());
        if (!save(comment)){
            return new ResponseResult(HttpStatusEnum.INSERT_DATA_ERROR);
        }

        return ResponseResult.ok();
    }



    @Override
    public long getCommentCountByArticleIdAndType(Integer articleId, Integer type) {
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getArticleId, articleId)
                .eq(Comment::getType, type)
                .eq(Comment::getParentId,SystemConstance.COMMENT_ROOT_ID)
                .eq(Comment::getIsReview, SystemConstance.IS_REVIEW);

        List<Comment> commentList = list(queryWrapper);
        int total = commentList.size();
        for (Comment comment : commentList) {
            List<Comment> childrenList = getChildrenListById(comment.getId(), SystemConstance.IS_REVIEW);
            if (Objects.nonNull(childrenList)){
                total += childrenList.size();
            }
        }
        return total;
    }


    @Override
    public List<Comment> getAllRootCommentsByType(Integer type) {
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getParentId, SystemConstance.COMMENT_ROOT_ID)
                .eq(Comment::getIsReview, SystemConstance.IS_REVIEW)
                .eq(Comment::getType, type)
                .orderByAsc(Comment::getCreateTime);
        return list(queryWrapper);
    }

    @Override
    public List<Comment> getAllChildrenCommentsByIdAndType(Integer commentId, Integer type) {
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getParentId, commentId)
                .eq(Comment::getIsReview, SystemConstance.IS_REVIEW)
                .eq(Comment::getType, type)
                .orderByAsc(Comment::getCreateTime);
        List<Comment> childrenList = list(queryWrapper);
        if (Objects.isNull(childrenList) || childrenList.size() <= 0) {
            return null;
        }
        ArrayList<Comment> comments = new ArrayList<>();
        for (Comment children : childrenList) {
            List<Comment> commentList = getAllChildrenCommentsByIdAndType(children.getId(), type);
            if (Objects.nonNull(commentList) && commentList.size() > 0) {
                comments.addAll(commentList);
            }
        }
        if (comments.size() > 0) {
            childrenList.addAll(comments);
        }

        return childrenList;
    }

    @Override
    public List<Comment> getArticleAllCommentListByIdAndType(Integer articleId, Integer type) {

        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getArticleId,articleId)
                .eq(Comment::getType,type);

        return list(queryWrapper);
    }




    private boolean checkAdmin(){

        try {
            LoginUser loginUser = SecurityUtils.getLoginUser();
            if (SystemConstance.ROLE_ADMIN_ID.equals(loginUser.getRole().getId())){
                return true;
            }
        } catch (Exception exception) {
            return false;
        }
        return false;
    }








    //    private Comment getRootComment(Integer parentId){
//        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(Comment::getId,parentId)
//                .eq(Comment::getIsReview,SystemConstance.IS_REVIEW);
//        Comment comment = getOne(queryWrapper);
//        if (Objects.isNull(comment)){
//            return null;
//        }
//        Comment rootComment = getRootComment(comment.getParentId());
//        if (Objects.nonNull(rootComment)){
//            return rootComment;
//        }
//        return comment;
//
//    }
//
//
//
//
//
//
//
//    private void delRedisCacheByCommentIds(List<Integer> commentIds){
//        List<Comment> comments = commentIds.stream()
//                .map(id -> {
//                    return getById(id);
//                }).collect(Collectors.toList());
//        delRedisCacheByComments(comments);
//    }
//
//
//    private void delRedisCacheByComments(List<Comment> commentList){
//        commentList.stream()
//                .peek(comment -> {
//                    if (SystemConstance.COMMENT_ROOT_ID.equals(comment.getParentId())){
//                        delRedisCacheByRootCommentIdAndType(comment.getId().toString(),comment.getType());
//                    }else {
//                        Comment rootComment = getRootComment(comment.getParentId());
//                        delRedisCacheByRootCommentIdAndType(rootComment.getId().toString(),rootComment.getType());
//                    }
//                }).collect(Collectors.toList());
//    }
//
//
//
//
//
//    private void delRedisCacheByArticleIdAndType(Integer articleId, Integer type) {
//
//        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(Comment::getArticleId,articleId)
//                .eq(Comment::getType,type)
//                .eq(Comment::getParentId,SystemConstance.COMMENT_ROOT_ID);
//        List<Comment> rootComments = list(queryWrapper);
//        rootComments.stream()
//                .peek(root -> delRedisCacheByRootCommentIdAndType(root.getId().toString(),root.getType()))
//                .collect(Collectors.toList());
//    }
//
//
//    private void setRedisCacheChildrenCommentList(String rootCommentId,Integer type,List<Comment> childrenList){
//        if (SystemConstance.ARTICLE_TYPE_BY_ARTICLE_CODE.equals(type)) {
//
//            redisCache.setCacheHashMap(SystemConstance.REDIS_ARTICLE_COMMENT_CHILDREN_KEY, rootCommentId,childrenList);
//
//        } else if (SystemConstance.ARTICLE_TYPE_BY_FRIEND_LINK_CODE.equals(type)) {
//
//            redisCache.setCacheHashMap(SystemConstance.REDIS_FRIEND_LINK_COMMENT_CHILDREN_KEY, rootCommentId,childrenList);
//
//        } else if (SystemConstance.ARTICLE_TYPE_BY_TALK_CODE.equals(type)) {
//
//            redisCache.setCacheHashMap(SystemConstance.REDIS_TALK_COMMENT_CHILDREN_KEY, rootCommentId,childrenList);
//        }
//    }
//
//
//    private List<Comment> getRedisChildrenCommentListByRootCommentIdAndType(String rootCommentId,Integer type){
//        List<Comment> childrenList = null;
//        if (SystemConstance.ARTICLE_TYPE_BY_ARTICLE_CODE.equals(type)) {
//
//            childrenList = redisCache.getCacheHashMapValue(SystemConstance.REDIS_ARTICLE_COMMENT_CHILDREN_KEY, rootCommentId);
//
//        } else if (SystemConstance.ARTICLE_TYPE_BY_FRIEND_LINK_CODE.equals(type)) {
//
//            childrenList = redisCache.getCacheHashMapValue(SystemConstance.REDIS_FRIEND_LINK_COMMENT_CHILDREN_KEY, rootCommentId);
//
//        } else if (SystemConstance.ARTICLE_TYPE_BY_TALK_CODE.equals(type)) {
//
//            childrenList = redisCache.getCacheHashMapValue(SystemConstance.REDIS_TALK_COMMENT_CHILDREN_KEY, rootCommentId);
//        }
//        return childrenList;
//    }
//
//
//    private void delRedisCacheByRootCommentIdAndType(String rootCommentId,Integer type){
//
//        if (SystemConstance.ARTICLE_TYPE_BY_ARTICLE_CODE.equals(type)) {
//
//            redisCache.delCacheHashMaps(SystemConstance.REDIS_ARTICLE_COMMENT_CHILDREN_KEY, rootCommentId);
//
//        } else if (SystemConstance.ARTICLE_TYPE_BY_FRIEND_LINK_CODE.equals(type)) {
//
//            redisCache.delCacheHashMaps(SystemConstance.REDIS_FRIEND_LINK_COMMENT_CHILDREN_KEY, rootCommentId);
//
//        } else if (SystemConstance.ARTICLE_TYPE_BY_TALK_CODE.equals(type)) {
//
//            redisCache.delCacheHashMaps(SystemConstance.REDIS_TALK_COMMENT_CHILDREN_KEY, rootCommentId);
//        }
//    }




}




